
/*
 * 将 ipcMain 通信单独封装一层
 *
 * ipc 通信，尽量在渲染进程中少使用 remote
 */
import { ipcMain, shell, dialog } from 'electron'
import { OPENFINDEREVENTKEY, OPENFINDEREVENTREPLYKEY, DISPLAYINFINDEREVENTKEY } from './constText.js'

export default function () {

    // 打开文件或文件夹，选择文件或文件夹
    ipcMain.on(OPENFINDEREVENTKEY, (event, param) => {
        dialog.showOpenDialog(param)
            .then(result => {
                if (result.filePaths.length) {
                    event.reply(OPENFINDEREVENTREPLYKEY, result.filePaths)
                }
            })
    })

    // Finder 中展示路径，仅展示
    ipcMain.on(DISPLAYINFINDEREVENTKEY, (event, param) => {
        shell.openPath(param)
    })
}